/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package casino;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Class for bins of the Roulette wheel. Each bin contains outcomes that should
 * win should that bin get selected by the wheel.
 *
 * @author  amaghfur
 * @since   1.0
 */
public class Bin {
    
    /** a set that holds the collection of individual outcomes */
    private Set<Outcome> outcomes = new HashSet<>();
    
    /**
     * Default constructor for a bin.
     */
    public Bin() {
    }
    
    /**
     * Constructor for bin which also loads array of outcomes from argument
     * to bin's outcome.
     * 
     */
    public Bin(Outcome[] newOutcomes) {
        outcomes = new HashSet<Outcome>(Arrays.asList(newOutcomes));
    }
    
    /**
     * Constructor for bin which also loads collection of outcomes from
     * from argument to bin's outcome.
     * 
     * @param outcomes 
     */
    public Bin(Collection<Outcome> outcomes) {
        Iterator<Outcome> itOutcomes = outcomes.iterator();
        while (itOutcomes.hasNext() == true) {
            outcomes.add((Outcome)itOutcomes.next());
        }
    }
    
    /**
     * Getter for outcomes
     */
    public Set<Outcome> getOutcomes() {
        return outcomes;
    }
    
    /**
     * Adds the argument outcome to this bin.
     * 
     */
    public void add(Outcome newOutcome) {
        outcomes.add(newOutcome);
    }
    
    /**
     * Returns an easy-to-read representation of the list of outcomes in this
     * bin.
     * 
     * @return 
     */
    @Override
    public String toString() {
        Iterator<Outcome> itOutcomes = outcomes.iterator();
        String text = "[ ";
        while(itOutcomes.hasNext() == true) {
            text = text + itOutcomes.next().toString() + ", ";
        }
        text = text.substring(0, text.length() - 2);
        return text + " ]";
    }
    
    /**
     * Get iterator for outcomes held by this bin.
     * 
     * @return  iterator of outcomes
     */
    public Iterator<Outcome> outcomeIterator() {
        return outcomes.iterator();
    }
}
